﻿using LPLS.Commons.DBModule;
using LPLS.DBEntities;
using LPLS.DBEntities.ConfigModels.AlarmModels;
using LPLS.DBInterface.ConfigModels.AlarmModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LPLS.DBServices.ConfigModels
{
    public class AlarmVarableConfigService : DBBaseService, IAlarmVarableConfigService
    {
        public AlarmVarableConfigService(DBContext dbContext) : base(dbContext)
        {
        }

     

        /// <summary>
        /// 添加数据    0：失败 1：成功
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public int InsertData(List<AlarmVarableConfig> data)
        {
            var client = DbContext.GetDbContext(DataBaseName);


            //先全部删除
            client.DeleteNav<AlarmVarableConfig>(it => data.Select(f=>f.VarName).Contains(it.VarName))
            .Include(z1 => z1.AlarmVarableCodeConfigs)
            .ExecuteCommand();
            ///强制插入
      return   client.InsertNav(data)
            .Include(z1 => z1.AlarmVarableCodeConfigs)
            .ExecuteCommand()? 1:0;



        }

        public List<AlarmVarableConfig> GetData()
        {
            var client = DbContext.GetDbContext(DataBaseName);

            var list = client.Queryable<AlarmVarableConfig>()
 .Includes(x => x.AlarmVarableCodeConfigs)
 .ToList();

            return list;
        }

        public override void InitDataBaseName()
        {
            DataBaseName= DatabaseEnum.SqliteConfig.ToString();
        }
    }
}
